const {SuccessModel, ErrorModel} = require('../model/ResModel')
const {registerUserNameNotExistInfo} = require('../model/ErrorInfo')
const {getMenuList} = require('../service/menu')

const getMenu = async (ctx) => {
  const user = ctx.session.user
  if (user) {
    const result = await getMenuList(user.role.auth)
    return result ? new SuccessModel(result) : new ErrorModel(registerUserNameNotExistInfo)
  } else {
    return new ErrorModel(registerUserNameNotExistInfo)
  }
}

const getMenuAll = async () => {
  const result = await getMenuList('all')
  return result ? new SuccessModel(result) : new ErrorModel(registerUserNameNotExistInfo)
}

module.exports = {
  getMenu,
  getMenuAll
}
